// pages/test/test.js

const data = require("../../utils/testProb.js").data

Page({

    /**
     * 页面的初始数据
     */
    data: {
        probs: [],
        curProb: 0,
        answer: []
    },

    textChanged: function(event) {
        let temp = "answer[" + this.data.curProb + "]"
        this.setData({
            [temp]: event.detail.value
        })
    },

    nextClicked: function() {
        this.setData({
            curProb: this.data.curProb + 1
        })
    },

    onSubmitClicked: function() {
        let hash = 0;
        for(let i = 0; i < this.data.answer.length; i++) {
            for(let j = 0; j < this.data.answer[i].length; j++) {
                hash += this.data.answer[i].charCodeAt(j)
            }
        }
        wx.navigateTo({
            url: "../result/result?hash=" + hash,
            fail: function() {
                console.log("navigate to result failed")
            }
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let temp = []
        for(let i = 0; i < data.length; i++) {
            temp.push("")
        }

        this.setData({
            probs: data,
            answer: temp
        })
    },
})